<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'add.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  	<div align="center"><h1>注册</h1></div>
  	<form action="add" method="post" id="myform" enctype="multipart/form-data">
    <table border="1" align="center">
    	<tr>
    		<td></td>
    		<td><input type="file" value="上传头像" name="a_path"/></td>
    	</tr>
    	<tr>
    		<td>新账号</td>
    		<td><input name="userAccount" onblur="dd()" /><span id="a"></span></td>
    	</tr>
    	<tr>
    		<td>新密码</td>
    		<td><input type="password" name="password"/><span id="b"></span></td>
    	</tr>
    	<tr>
    		<td>确认密码</td>
    		<td><input type="password" name="chePassword"/><span id="c"></span></td>
    	</tr>
    	<tr>
    		<td>邮箱</td>
    		<td><input name="email" type="email"/><span id="d"></span></td>
    	</tr>
    	<tr>
    		<td>部门</td>
    		<td>
    			<select name="deptId">
    					<option value="0">请选择</option>
    					<c:forEach var="list" items="${list}">
    						<option value="${list.deptId }">${list.deptName }</option>
    					</c:forEach>
    				</select>
    				<span id="e"></span>
    		</td>
    	</tr>
    	<tr>
    		<td colspan="2"><input type="submit" value="注册"/>
    		<a href="index.jsp"><input type="button" value="取消"/></a></td>
    	</tr>
    </table>
    </form>
  </body>
  <script type="text/javascript" src="js/jquery-1.12.4.js"></script>
  <script type="text/javascript">
  	$(function(){
  		$("#myform").submit(function(){
  		 	var a = $("[name=password]").val();
  		 	var b = $("[name=chePassword]").val();
  		 	if($("[name=userAccount]").val() == ""){
  		 		$("#a").html("账号不能为空");
  		 		return false;
  		 	}
  			if(a==""){
  				$("#b").html("密码不能为空");
  				return false;
  			}
  			if(b==""){
  				$("#c").html("密码不能为空");
  				return false;
  			}
  			if(a!= b){
  				$("#c").html("两次密码不一样");
  				return false;
  			}
  			if($("[name=email]").val()==""){
  				$("#d").html("邮箱不能为空");
  				return false;
  			}
  			if($("[name=deptId]").val()==0){
  				$("#e").html("部门不能为空");
  				return false;
  			}
  			
  		});
  	});
  	function dd(){
  		var name = $("[name=userAccount]").val();
  		$.post("cheName","name="+name,function(data){
  			if(data=="false"){
  				$("#a").html("名称已存在");
  			}else{
  				$("#a").html("名称不存在");
  			}
  		});
  	}
  </script>
</html>
